package org.vectrics.company.client;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.vectrics.VectricsException;
import org.vectrics.client.webclient.CommandDispatcher;
import org.vectrics.company.Company;



public class CompanyDataManager {
	private static CompanyDataManager instance = new CompanyDataManager();

	
	public CompanyDataManager() {
		super();
	}

	
	static public CompanyDataManager getInstance() {
		return(instance);
	}
	
	
	public Collection getCompaniesNameMatch(String companyName) {
		Vector companies = new Vector();
		return(companies);
	}

	
	public List findAllCompanies() {
		Vector companyList = new Vector(20);
		FindCompanyIds findCompanyIdsCommand = new FindCompanyIds();
		CommandDispatcher.getInstance().execute(findCompanyIdsCommand);
		List list = findCompanyIdsCommand.getCompanyIdList();
		Iterator iter = list.iterator();
		while (iter.hasNext()) {
			Long id = (Long)iter.next();
			FindCompany findCompanyCommand = new FindCompany();
			findCompanyCommand.setCompanyId(id);
			CommandDispatcher.getInstance().execute(findCompanyCommand);
			Company company = findCompanyCommand.getCompany();
			companyList.add(company);
		}
		return(companyList);
	}
		
	
}
